<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"
    import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>系統設定</title>
</head>
<body>
<% if(session.getAttribute("access") == "y" ){%>
<jsp:useBean id="mydb" scope="page" class="bean.ConDbBean"/> <%//連結資料庫的bean %>
<jsp:useBean id="p_page" scope="page" class="bean.PageBean"/>
<table width="750" border="0" align="center">
  <tr>
    <td width="30" rowspan="4"><jsp:include page="../frameset/left.jsp" flush="true" ></jsp:include></td>
    <td colspan="2"><jsp:include page="../frameset/top.jsp" flush="true" ></jsp:include></td>
    <td width="40" rowspan="4"><jsp:include page="../frameset/right.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td rowspan="2"><jsp:include page="../frameset/mean.jsp" flush="true" ></jsp:include>

    </td>
    <td height="32"><jsp:include page="../frameset/setting_mean.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td>
   <%--內頁--%>
    		
    		<% 
	  		String sql="select * from SYS_SETTING";
	  		ResultSet rs=mydb.executeQuery(sql); 
	  		sql="select COUNT(S_ID) from SYS_SETTING"; //算total筆數
	  		ResultSet rs3=mydb.executeQuery(sql); 
	  		rs3.next();
	  		
	  		int nTotal=java.lang.Integer.valueOf(rs3.getString(""));
	  		p_page.init(nTotal);
	  		
	  		int now_page;
	  		if(request.getParameter("Page")==null){
	  			p_page.getPage(0);
	  			now_page=0;
	  		}
	  		else{
	  		    int nPage=java.lang.Integer.valueOf(request.getParameter("Page"));
	  			p_page.getPage(nPage);
	  			now_page=p_page.getNowPage();
	  		}
	  		int nTf=p_page.getnTf();
	  		
	  		%>
	  		
	  		<table>
        		<tr>
        			<td><a href="addsetting.jsp" target="_self" class="style2"><img src="image/new_setting.jpg" width="120" height="25" / border="0"></a></td>
        		</tr>   <!-- 新增系統設定資料 -->
        	</table> 
        <% 
	  		if(nTotal==0){
			%>
    			
	  			<table width="500" border="0" bordercolor="#999999" align="center">
      				<tr>
      					<td>資料庫裡尚未儲存資料</td>
      				</tr>
      			</table>
      	 	<%
	  		}
	  		else
	  		{
			%>
	  			<table width="550" border="0" align="center">
	  				<tr>
    				<td><form id="form1" name="form1" method="post" action="do_delmember.jsp">
      					<table width="100%" border="1">
      						<tr>
          						<td>編號</td>
          						<td>設定名稱</td>
          						<td>設定值</td>
								<td>修改</td>
          						<td><input type="submit" name="Submit" value="刪除" /></td>
        					</tr>
        					
<%
							int index;
							if(request.getParameter("Page")!=null){
									int page_next=p_page.getRecordBegin();
									if(page_next!=0){
									rs.absolute(page_next);
									}
								}
							for(index=p_page.getRecordBegin();index<nTf;index++){
								rs.next();
	  			
%>
        					<tr>
          						
          						<td><a href="detailsetting.jsp?id=<%=rs.getString("S_ID")%>" target="_black" class="style2"><%=rs.getString("S_ID")%></a></td>
          						<td><%=rs.getString("S_NAME")%></td>
								<td><%=rs.getString("S_VALUE")%></td>
          						<td><a href="altersetting.jsp?id=<%=rs.getString("S_ID")%>" target="_self" class="style2"><img src="../image/modify.gif" / border="0"></a></td>
          						<td><input name="del" type="checkbox" value="<%=rs.getString("S_ID")%>" /></td>
        					</tr>
<%
	  						}
%>
	  					</table>
<%    		
			}
 %>
 
    </form>
		</td>
  		</tr>
	</table>
	
	<%--分頁處理--%>
	
	<form method="post" name="PageChange" action="lookSetting.jsp">
    <table border=0 cellpadding=2 cellspacing=0 width=60% align="center"> 
	 
      <tr>
        <td>
          <% 
          if ( p_page.getNowPage() > 0 ) {%>
            <a href="JavaScript:showPage(<%= now_page-1%>);">上一頁</a>
          <%
          }
          // 計算總頁數
          int PageTotal = p_page.getPageTotal();
          %>
          <font class="myFont_9G">
        	&nbsp; 第&nbsp;<%=now_page+1%>&nbsp;頁，
          	共&nbsp;<%=PageTotal%>頁，
          </font>
          <%
          if ( PageTotal > (now_page + 1) ) {%>
            <a href="JavaScript:showPage(<%= now_page+1%>);"> 下一頁</a>
          <%
          }%>　
            <input type="hidden" name="Page" value="">
           
            <select name="PageSelect"
                onChange="JavaScript:showPage(document.PageChange.PageSelect.selectedIndex - 1);">
              <option value="">快速換頁
            <%
            for ( int b=1; b<=PageTotal; b++ )
              out.print("<option value="+b+">第 "+b+" 頁");%>
            </select>
        </td>
      </tr>
    </table>
	</form>
	<%--分頁處理end--%>
	
	<%--內頁end--%>
   
    </td>
  </tr>
  <tr>
    <td colspan="2"></td>
  </tr>
</table>
<script language="JavaScript">
function showPage(Page) {
  document.PageChange.Page.value = Page;
  document.PageChange.submit();
}
</script>
<%
  }
  else{
  	response.sendRedirect("../index.jsp"); //若沒有登入則回到index.jsp
  } 
  %>
</body>
</html>
